﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cludg.Services.Security
{
    using Repository.Security;

    internal abstract class ValidateUserStrategy
    {
        public abstract string ValidateUser(ISecurityRepository repository, Principal principal);
        public abstract bool IsForPrincipal(Principal principal);
    }

    internal abstract class ValidateUserStrategy<TPrincipal> : ValidateUserStrategy where TPrincipal : Principal
    {
        protected abstract string DoValidateUser(ISecurityRepository repository, TPrincipal principal);

        public override string ValidateUser(ISecurityRepository repository, Principal principal)
        {
            System.Diagnostics.Debug.Assert(principal is TPrincipal);
            System.Diagnostics.Debug.Assert(repository != null);

            return DoValidateUser(repository, principal as TPrincipal);
        }

        public override bool IsForPrincipal(Principal principal)
        {
            return principal is TPrincipal;
        }
    }
}
